package xiao_jin.fantastic_journey.core.init;

import club.someoneice.cookie.util.ObjectUtil;
import com.google.common.collect.Lists;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Blocks;
import net.minecraft.block.FluidBlock;
import net.minecraft.fluid.FlowableFluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import xiao_jin.fantastic_journey.FantasticJourney;
import xiao_jin.fantastic_journey.core.common.fluid.FluidOil;
import xiao_jin.fantastic_journey.util.ModUtil;

public final class ModFluids {
    public static final FlowableFluid OIL = reg(new FluidOil.Still(), "fluid_oil_still");
    public static final FlowableFluid OIL_FLOWING = reg(new FluidOil.Flowing(), "fluid_oil_flowing");
    public static final FluidBlock FLUID_OIL = regFluidBlock(OIL, "block_fluid_oil");
    public static final BucketItem BARREL_MECHROIL = registerItem("barrel_mechroil", new BucketItem(OIL, (new Item.Settings()).recipeRemainder(Items.BUCKET).maxCount(1)), ModItemGroup.Sundries);

    public static boolean isInOil(FluidState state) {
        return state.isOf(OIL) || state.isOf(OIL_FLOWING);
    }

    private static FlowableFluid reg(final FlowableFluid fluid, final String name) {
        return Registry.register(Registries.FLUID, ModUtil.getIdOfMod(name), fluid);
    }

    private static FluidBlock regFluidBlock(FlowableFluid fluid, String name) {
        return Registry.register(Registries.BLOCK, ModUtil.getIdOfMod("block_" + name),
                new FluidBlock(fluid, AbstractBlock.Settings.copy(Blocks.WATER)));
    }

    private static BucketItem registerItem(String name, BucketItem item, ModItemGroup group) {
        Registry.register(Registries.ITEM, ModUtil.getIdOfMod(name), item);
        var map = FantasticJourney.ITEM_GROUP_MAP;
        map.put(group, ObjectUtil.objectRun(map.getOrDefault(group, Lists.newArrayList()), it -> {
            it.add(item);
        }));
        return item;
    }

    public static void registerFluids() {
    }
}
